// 左移出现删除按钮
 window.onload=function(){
	    setSlide();
	    var elems=document.getElementsByClassName("action-delete");
	    for(var i=0;i<elems.length;i++){
	        elems[i].addEventListener("click", function(){     
	            var r=confirm("确定要删除该记录吗?")
	            if (r){
	              alert("已删除");
	            }
	        });
	    }
	 };
	 
function setSlide() {
	    //侧滑显示删除按钮
	    var expansion = null; //是否存在展开的list
	    var container = document.querySelectorAll(".swipe-container");
	    for (var i = 0; i < container.length; i++) {
	        var x, y, X, Y, swipeX, swipeY;
	        container[i].addEventListener('touchstart', function (event) {
	            x = event.changedTouches[0].pageX;
	            y = event.changedTouches[0].pageY;
	            swipeX = true;
	            swipeY = true;
	            if (expansion) { //判断是否展开
	                //如果展开则收起 以下代码取消注释后则滑动开始立即收起 注释后则向右滑动一定距离后收起隐藏按钮
	                //方法一.
	                //removeClass(this,"swipeleft");
	                //方法二 需引入jquery
	                //$(this).removeClass("swipeleft");
	            }
	        });
	        container[i].addEventListener('touchmove', function (event) {
	            X = event.changedTouches[0].pageX;
	            Y = event.changedTouches[0].pageY;
	            // 左右滑动
	            if (swipeX && Math.abs(X - x) - Math.abs(Y - y) > 0) {
	                // 阻止事件冒泡
	                event.stopPropagation();
	                if (X - x > 10) { //右滑收起
	                    event.preventDefault();
	                    removeClass(this,"swipeleft");
	                    //$(this).removeClass("swipeleft");
	                }
	                if (x - X > 10) { //左滑展开
	                    event.preventDefault();
	                    //$(this).addClass("swipeleft");
	                    addClass(this,"swipeleft");
	                    expansion = this;
	                }
	                swipeY = false;
	            }
	            // 上下滑动
	            if (swipeY && Math.abs(X - x) - Math.abs(Y - y) < 0) {
	                swipeX = false;
	            }
	        });
	    }
	}
	
function hasClass(elem, cls) {
	    cls = cls || '';
	    if (cls.replace(/\s/g, '').length == 0) return false;
	    return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
	  }
	   
function addClass(ele, cls) {
	    if (!hasClass(ele, cls)) {
	      ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
	    }
	  }
	   
function removeClass(ele, cls) {
	    if (hasClass(ele, cls)) {
	      var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
	      while (newClass.indexOf(' ' + cls + ' ') >= 0) {
	        newClass = newClass.replace(' ' + cls + ' ', ' ');
	      }
	      ele.className = newClass.replace(/^\s+|\s+$/g, '');
	    }
	  }

$(".listR i").click(function(){
	$(this).toggleClass("click");
})


// 长按事件
$.fn.longPress = function(fn) {
    var timeout = undefined;
    var $this = this;
    for(var i = 0;i<$this.length;i++){
        $this[i].addEventListener('touchstart', function(event) {
            timeout = setTimeout(fn, 1000);
            }, false);
        $this[i].addEventListener('touchend', function(event) {
            clearTimeout(timeout);
            }, false);
    }
}


// 代码使用
$(".mail_list .swipe-container dd").longPress(function(){
	$(".mailBody").addClass("show")
});


// 全选
$(".footShow .qxBtn").click(function(){
  		var cs=document.getElementsByName("check"); 
         for(i=0;i<cs.length;i++){ 
            cs[i].checked=event.srcElement.checked; 
                    			 } 
  		
		})
$(".footShow .cancelBtn").click(function(){
	$(".mailBody").removeClass("show")
})
$(".footShow .delBtn").click(function(){
	var del=confirm("确定要删除该记录吗?")
	if (del){
	  alert("已删除");
	}
})

$(".screenIcon").click(function(){
	$(".fixTop").stop().fadeToggle("fast")
})


$(".flexible").click(function(){
	$(".mask").stop().fadeIn("fast");
	$(".menuL").addClass("open");
})


function stopPropagation(e) {
	if (e.stopPropagation) 
	e.stopPropagation();
	else 
	e.cancelBubble = true;
}
	
$(".mask").bind('click',function(){
	$('.menuL').removeClass("open");
	$(".mask").stop().fadeOut("fast");
});
	
$(".menuL").bind('click',function(e){
	stopPropagation(e);
});

$(".menuL ul li").click(function(){
	$(this).addClass("active").siblings().removeClass("active")
})